const { merge } = require('webpack-merge')
const commonConfig = require('./webpack.config.common.js')
const productionConfig = require('./webpack.config.prod.js')
const developmentConfig = require('./webpack.config.dev')

// 设置为函数形式，允许通过脚本传入环境变量的参数
module.exports = (env) => {
  // 这种方式脚本传递参数时是 --env development 或者 --env production，相当于 env.development 设置为 true
  // switch (true) {
  //   case env.development:
  //     return merge(commonConfig, developmentConfig)
  //   case env.production:
  //     return merge(commonConfig, productionConfig)
  //   default:
  //     throw new Error('No matching configuration was found!')
  // }

  // 这种方式需要传递键值对 --env type=dev
  let mergeObj = {
    dev: developmentConfig,
    prod: productionConfig
  }
  if (mergeObj[env.type]) {
    return merge(commonConfig, mergeObj[env.type])
  } else {
    throw new Error('No matching configuration was found!')
  }
}